﻿using System;
using System.Runtime.Serialization;
#if !MONO
using System.Device.Location;
#endif

namespace Ping.Core
{
	/// <summary>
	/// It seems that Mono is missing an implementation for the GeoCoordinate class,
	/// hence I'm rolling my own.
	/// </summary>
	[DataContract]
	public class GeoPosition
	{
		private double _lat;
		private double _lon;

		[DataMember]
		public double Latitude
		{
			get { return _lat; }
			set
			{
				if (value < -90 || value > 90)
					throw new ArgumentOutOfRangeException();
				_lat = value;
			}
		}

		[DataMember]
		public double Longitude
		{
			get { return _lon; }
			set
			{
				if (value < -180 || value > 180)
					throw new ArgumentOutOfRangeException();
				_lon = value;
			}
		}

#if !MONO
		public GeoCoordinate AsGeoCoordinate
		{
			get
			{
				return new GeoCoordinate
				       	{
				       		Latitude = _lat,
				       		Longitude = _lon,
				       	};
			}
		}
#endif
	}
}